import java.util.*;

public class Test {

    static int n;
    static int m;

    static int[] startPoint;
    static int[] finishPoint;

    static int[][] table;

    static int[][] tmp;

    static int[][] visited;
    static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {

        getInput();

        // print();
        System.out.println(solveProblem(startPoint[0], startPoint[1], finishPoint[0], finishPoint[1]));

        print();
        input.close();
    }

    static int solveProblem(int x1, int y1, int x2, int y2) {

        if (x1 == x2 && y1 == y2) {
            return 0;
        }

        else {

            if (tmp[x1][y1] == 0) {

                int a = Integer.MAX_VALUE / 2;
                int b = Integer.MAX_VALUE / 2;

                int tag1 = 0;
                int tag2 = 0;
                if (x1 != x2) {

                    tag1 = x1 < x2 ? 1 : -1;
                    a = Math.abs(table[x1][y1] - table[x1 + tag1][y1]) + solveProblem(x1 + tag1, y1, x2, y2);

                }

                if (y1 != y2) {
                    tag2 = y1 < y2 ? 1 : -1;

                    b = Math.abs(table[x1][y1] - table[x1][y1 + tag2]) + solveProblem(x1, y1 + tag2, x2, y2);

                }
                if (a < b) {
                    visited[x1 + tag1][y1] = 1;
                    visited[x1][y1 + tag2] = 0;
                }

                if (b < a) {
                    visited[x1][y1 + tag2] = 1;
                    visited[x1 + tag1][y1] = 0;
                }
                tmp[x1][y1] = Math.min(a, b) + 1;
            }

            return tmp[x1][y1];
        }
    }

    static void getInput() {
        int i;
        int j;

        n = input.nextInt();
        m = input.nextInt();
        input.nextLine();

        String s = input.nextLine();

        table = new int[m][n];
        tmp = new int[m][n];
        visited = new int[m][n];
        startPoint = new int[2];
        finishPoint = new int[2];

        for (i = 0; i < m; i++) {
            for (j = 0; j < n; j++) {
                table[i][j] = input.nextInt();
            }
        }

        s = s.replace(" ", "");

        s = s.substring(1, s.length() - 1);

        String[] pointString = s.split("\\)\\(");

        for (i = 0; i < 2; i++) {
            startPoint[i] = Integer.parseInt(pointString[0].split(",")[1 - i]) - 1;
            finishPoint[i] = Integer.parseInt(pointString[1].split(",")[1 - i]) - 1;
        }

    }

    static void print() {
        System.out.println();
        int i;
        int j;

        System.out.println(startPoint[0] + " " + startPoint[1]);
        System.out.println(finishPoint[0] + " " + finishPoint[1]);

        for (i = 0; i < m; i++) {
            for (j = 0; j < n; j++) {
                System.out.print(tmp[i][j] + " ");
            }
            System.out.println();
        }

    }
}

// 316